<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>按年龄查询</title>
</head>
<link rel="stylesheet" href="css/header.css">


<body background="resourse/bg.jpg">
<%//判断是否登录
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);
    if (userid!=null) {
%>

<div id="header"><!--页头-->
    <spana>&emsp;巴以小记</spana>
    <br>
    <spanb>&emsp;&emsp;<%=(String)session.getAttribute("userid")%> 在线中..</spanb>
    <ul>
        <li></li>
        <li><h2 class="main" ><a class="btna" href="main.jsp">主页</a></h2></li>
        <li><h2 class="work"><a class="btna" href="addInfo.jsp">发贴</a></h2></li>
        <li><h2 class="new"><a class="btna" href="showInfo.jsp" >看贴</a></h2></li>
        <li><h2 class="comment"><a class="btna" href="showInfo.jsp" >搜索</a></h2></li>
    </ul>
</div>
<br>

        <%
        request.setCharacterEncoding("UTF-8");
        String pick = request.getParameter("pick");
        Connection conn = null;
        Statement stat = null;
        ResultSet rs = null;
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/talknewsdatabase";
        String user = "root";
        String password = "123456";
        conn = DriverManager.getConnection(url, user, password);
        stat = conn.createStatement();
        rs = stat.executeQuery("select * from info where  user_id='" +userid +  "' and pick=" + pick + "");

    %>



    <center>     
        <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt">

            <%
                if (rs.next()) {
                    out.print("<tr><td colspan=\"3\"><h3><strong>" + rs.getString("title") + "</strong></h3></td></tr>");

                    out.print("<tr><td> ID:" + rs.getString("id") + "</td>");
                    out.print("<td>" + rs.getString("name") + "</td>");

                    out.print("<tr><td colspan=\"3\" > <textarea readonly rows=\"20\" cols=\"70\" style=\"font-size:20px\">"+rs.getString("comment")+"</textarea></td></tr>");

            %>
            <tr>
                <td><a href="delete.jsp?id=<%=rs.getString("id") %>">删除</a></td>
                <td><a href="update.jsp?id=<%=rs.getString("id") %>">修改</a></td>
                <td><a href="showInfo.jsp">返回信息页</a></td>
            </tr>
            <%
                } else {
                    out.print("<script>alert('不存在此信息！');" +
                            "window.location='http://localhost:8080/showInfo.jsp';</script>");
                }
            %>
        </table>

    </center>
          

    <%
        if (rs != null) {
            rs.close();
            rs = null;
        }
        if (stat != null) {
            stat.close();
            stat = null;
        }
        if (conn != null) {
            conn.close();
            conn = null;
        }
    %>

<%
    } else {
    out.print("<script>alert('未成功登录！');" +
    "window.location='http://localhost:8080/index.html';</script>");
    }
%>
  
</body>
</html>